package com.warren.blog.controller;

import com.warren.blog.pojo.Book;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.ArrayList;
import java.util.List;


@RestController
@Api("book crud接口")
@Slf4j
public class MainController {
    static {

    }

    @GetMapping("/book")
    @ApiOperation("获得所有书")
    public List<Book> getAllBooks() {
        log.info("hello");
        List<Book> books = new ArrayList<>();
        books.add(new Book(1, "小故事", "白雪公主", "故事类"));
        books.add(new Book(2, "小故事", "白雪公主", "故事类"));
        books.add(new Book(3, "小故事", "白雪公主", "故事类"));
        books.add(new Book(4, "小故事", "白雪公主", "故事类"));
        return books;
    }

    @GetMapping("/book/{id}")
    @ApiOperation("获得book")
    public Book getBook(@PathVariable("id") String id) {
        Book book = new Book(1, "小故事", "白雪公主", "故事类");
        return book;
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("删除book")
    public void deleteBook(@PathVariable(value = "id") String id) {
        System.out.println(id);
    }

    @PostMapping("/book")
    @ApiOperation("存储book")
    public int saveBook(@RequestBody Book book) {
        return 1;
    }

    @PutMapping("/book")
    @ApiOperation("更新")
    public Book update(@RequestBody Book book) {
        return  book;
    }
}
